﻿using System;

using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
using LetsDoIt.Forms;
using LetsDoIt.Localization;
using LetsDoIt.Properties;

namespace LetsDoIt.Controls
{
	public partial class CasePanel : UserControl
	{
		public event EventHandler CaseGetsDirty;

		public CasePanel()
		{
			InitializeComponent();
			txtDescription.TextChanged += new EventHandler(txtDescription_TextChanged);
			chkDifficultAccessEx.CheckedImage = Properties.Resources.checked_64;
            chkDifficultAccessEx.UncheckedImage = Properties.Resources.unchecked_64;
            chkDifficultAccesOnRainEx.CheckedImage = Properties.Resources.checked_64;
            chkDifficultAccesOnRainEx.UncheckedImage = Properties.Resources.unchecked_64;
            chkIsDispersed.CheckedImage = Properties.Resources.checked_64;
            chkIsDispersed.UncheckedImage = Properties.Resources.unchecked_64;
		}

		void txtDescription_TextChanged(object sender, EventArgs e)
		{
			SetCaseDirty();
		}

		private void SetCaseDirty()
		{
			if (CaseGetsDirty != null)
				CaseGetsDirty(this, EventArgs.Empty);
		}

		private void trkDiameter_ValueChanged(object sender, EventArgs e)
		{
		    UpdateDiameter();
		    SetCaseDirty();
		}

	    private void UpdateDiameter()
	    {
	        lblDiameter.Text = string.Format(
	            ResourceManager.Instance.GetString(@"MainForm_lblDiameter"),
	            trkDiameter.Value);
	    }

	    private void trkHeigth_ValueChanged(object sender, EventArgs e)
	    {
	        UpdateHeight();
	        SetCaseDirty();
	    }

	    private void UpdateHeight()
	    {
	        lblHeight.Text = string.Format(
	            ResourceManager.Instance.GetString(@"MainForm_lblHeight"),
	            trkHeigth.Value);
	    }

	    private void trkNotRecyclable_ValueChanged(object sender, EventArgs e)
	    {
	        UpdateNotRecyclable();
	        SetCaseDirty();
	    }

	    private void UpdateNotRecyclable()
	    {
	        lblNotRecyclable.Text = string.Format(
	            ResourceManager.Instance.GetString(@"MainForm_lblNotRecyclable"),
	            trkNotRecyclable.Value);
	    }

	    private void trkGlassContent_ValueChanged(object sender, EventArgs e)
	    {
	        UpdateGlassContent();
	        SetCaseDirty();
	    }

	    private void UpdateGlassContent()
	    {
	        lblGlassContent.Text = string.Format(
	            ResourceManager.Instance.GetString(@"MainForm_lblGlassContent"),
	            trkGlassContent.Value);
	    }

	    private void trkMetalContent_ValueChanged(object sender, EventArgs e)
	    {
	        UpdateMetalContent();
	        SetCaseDirty();
	    }

	    private void UpdateMetalContent()
	    {
	        lblMetalContent.Text = string.Format(
	            ResourceManager.Instance.GetString(@"MainForm_lblMetalContent"), 
	            trkMetalContent.Value);
	    }

	    private void trkPlasticContent_ValueChanged(object sender, EventArgs e)
	    {
	        UpdatePlasticContent();
	        SetCaseDirty();
	    }

	    private void UpdatePlasticContent()
	    {
	        lblPlasticContent.Text = string.Format(
	            ResourceManager.Instance.GetString(@"MainForm_lblPlasticContent"), 
	            trkPlasticContent.Value);
	    }

	    private void trkPaperContent_ValueChanged(object sender, EventArgs e)
	    {
	        UpdatePaperContent();
	        SetCaseDirty();
	    }

	    private void UpdatePaperContent()
	    {
	        lblPaperContent.Text = string.Format(
	            ResourceManager.Instance.GetString(@"MainForm_lblPaperContent"), 
	            trkPaperContent.Value);
	    }

	    private void trkRubberContent_ValueChanged(object sender, EventArgs e)
	    {
	        UpdateRubberContent();
	        SetCaseDirty();
	    }

	    private void UpdateRubberContent()
	    {
	        lblRubberContent.Text = string.Format(
	            ResourceManager.Instance.GetString(@"MainForm_lblRubberContent"), 
	            trkRubberContent.Value);
	    }

	    private void trkMaterialsContent_ValueChanged(object sender, EventArgs e)
	    {
	        UpdateMaterialsContent();
	        SetCaseDirty();
	    }

	    private void UpdateMaterialsContent()
	    {
	        lblMaterialsContent.Text = string.Format(
	            ResourceManager.Instance.GetString(@"MainForm_lblMaterialsContent"), 
	            trkMaterialsContent.Value);
	    }

        private void trkBagEq_ValueChanged(object sender, EventArgs e)
        {
            UpdateBagEq();
            SetCaseDirty();
        }

	    private void UpdateBagEq()
	    {
            lblBagEq.Text = string.Format(
                ResourceManager.Instance.GetString(@"MainForm_lblBagEq"),
                trkBagEq.Value);
	    }

        private void trkWidth_ValueChanged(object sender, EventArgs e)
        {
            UpdateWidth();
            SetCaseDirty();
        }

	    private void UpdateWidth()
	    {
            lblWidth.Text = string.Format(
                 ResourceManager.Instance.GetString(@"MainForm_lblWidth"),
                 trkWidth.Value);
	    }

        private void trkLength_ValueChanged(object sender, EventArgs e)
        {
            UpdateLength();
            SetCaseDirty();
        }

	    private void UpdateLength()
	    {
            lblLength.Text = string.Format(
                 ResourceManager.Instance.GetString(@"MainForm_lblLength"),
                 trkLength.Value);
	    }

        public void UpdateValues()
        {
            UpdateDiameter();
            UpdateHeight();
            UpdateNotRecyclable();
            UpdateGlassContent();
            UpdateMetalContent();
            UpdatePlasticContent();
            UpdatePaperContent();
            UpdateRubberContent();
            UpdateMaterialsContent();
            UpdateBagEq();
            UpdateWidth();
            UpdateLength();
        }
	}
}
